#! /usr/bin/env python3
import json
import sys
from convertMdUtil import loadCode
_PLATFORM = "win" in sys.platform and "windows" or "linux"


def get_config(path="config.json"):
    with open(path, "r+", encoding="utf-8") as f:
        json_dict = json.load(f)
        return json_dict


def get_md_html(body, sel):
    head = "Content-type:text/html\n\n"
    with open("html/md.web", "r", encoding="UTF-8") as f:
        constent = f.read()
        constent = constent.format(name="Program", main=body, ci_float=sel)
        return head + constent


if __name__ == '__main__':
    config = get_config()
    note_path = config.get("note_path", {}).get(_PLATFORM, None)
    content = get_md_html(loadCode.main(note_path), sel="")
    print(content)
